<?php

class FoodPlaces extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if (!$this->IsPostBack)
		{
			$this->Master->pageHead->Title = $this->Application->Parameters["WEBSITE_TITLE"] . " - Food Places";
			$this->Master->cssMenuFoodPlace->Value = "current_menu_item";
			
			// Populate Cuisine List
			$this->cboCuisineSelector->DataSource = CuisineRecord::finder()->getAllItems();
			$this->cboCuisineSelector->DataBind();
			
			// Populate MRT List
			$this->cboMRTSelector->DataSource = MRTRecord::finder()->getAllItems();
			$this->cboMRTSelector->DataBind();
			
			// Populate Close Time List
			$this->cboCloseTimeSelector->DataSource = CloseTimeRecord::finder()->getAllItems();
			$this->cboCloseTimeSelector->DataBind();
			
			$sql = "";
			if ($this->Request->contains('mrt') && $this->Request['mrt'] != '') {
				$sql .= " and f.nearest_mrt = " . $this->Request['mrt'];
				$this->cboMRTSelector->SelectedValue = $this->Request['mrt'];
			}
			
			if ($this->Request->contains('time') && $this->Request['time'] != '') {
				$sql .= " and f.open_until >= " . $this->Request['time'];
				$this->cboCloseTimeSelector->SelectedValue = $this->Request['time'];
			}
			
			if ($this->Request->contains('cid') && $this->Request['cid'] != '') {
				$sql .= " and fc.cuisine_id = " . $this->Request['cid'];
				$this->cboCuisineSelector->SelectedValue = $this->Request['cid'];
			}
			
			//$this->renderBoxRecommendedFoodPlaces($sql);
		}
	}
	
	protected function renderBoxRecommendedFoodPlaces($sql)
	{
		
		$limit = null;
		$offset = null;
		$sqlmap = $this->Application->Modules['sqlmap']->Client;
		$items = $sqlmap->queryForList("SearchFoodPlace",array("ADDITIONAL_CONDITION"=>$sql),null,$offset,$limit);
		$this->ListRecommendedFoodPlace->DataSource = $items;
		$this->ListRecommendedFoodPlace->DataBind();	
	}
}

?>